
import 'package:get/get.dart';
import 'package:guochaoapp/common/constant/api.dart';
import 'package:guochaoapp/common/utils/http_client.dart';
import 'package:guochaoapp/controller/home/home_controller.dart';
import 'package:guochaoapp/model/userdealers_entity.dart';
import 'package:guochaoapp/services/user_service.dart';

class GCSelectRegionController extends GetxController {

  UserService userService = Get.find();

  RxList<UserdealersData> dealersList = RxList.empty();

  /*请求经销商列表数据*/
  requestUsersDealers() {

    HttpClient.request<UserdealersEntity>(
      url: UserDealersApi.dealers,
      method: Method.GET,
      onSuccess: (_, model) {
        dealersList.assignAll(model.data);
      },
      onFailed: (error) {

      }
    );

  }

  /*点击地区*/
  didSelectedRegion(int index) {

    userService.dealerId = dealersList[index].dealerId;
    
    Get.find<GCHomeController>().reloadStateWithDealer(dealersList[index]);
    Get.back();

  }

}